home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PriortyQ.h
-
- Contains: Priority-Queue data structure.
-
- Owned by: Jens Alfke
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Theory of Operation:
-
- A Priority Queue is a sorted collection that allows entries to be added to
- the queue in arbitrary order, and allows the first (in sort order) entry
- -- and only the first entry -- to be viewed and removed. Its implementation
- makes it very efficient, using a partially sorted data structure called a
- heap. Any standard algorithms textbook will describe this; see Sedgewick's
- "Algorithms in C++", ch.11.
- */
-
-
- #ifndef _PRIORTYQ_
- #define _PRIORTYQ_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
-
- //=============================================================================
- // Queue-element mix-in class
- //=============================================================================
-
- // Objects you put in the queue must inherit from this abstract mix-in class.
-
- class Sortable {
- public:
- ODVMethod ODBoolean ComesBefore( const Sortable* ) const
- =0;
- };
-
-
- //=============================================================================
- // PriorityQueue
- //=============================================================================
-
-
- class PriorityQueue {
- public:
- PriorityQueue( ODULong suggestedSize =0 );
- virtual ~PriorityQueue( );
-
- ODMethod void Add( const Sortable* );
- ODMethod Sortable* GetFirst( ) const;
- ODMethod Sortable* RemoveFirst( );
- inline void RemoveAll( ) {fLast = 0;}
- ODMethod void DeleteAll( );
-
- inline ODBoolean IsEmpty( ) const {return fLast==0;}
-
- private:
- ODULong fSize;
- ODULong fLast;
- const Sortable* *fHeap; // Points to array of Sortable*s
- };
-
- #endif /*_PRIORTYQ_*/
-